import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public final class Person01 {
    //1.成员对象声明为 private final
    private final String name;
    private final int age;
    private final List<String> hobbies;

    //通过构造方法进行初始化
    public Person01(int age, String name, List<String> hobbies) {
        this.age = age;
        this.name = name;
        //对可变对象进行深拷贝 （防御性拷贝）
        this.hobbies = new ArrayList<>(hobbies);
    }

    //不提供setter

    public int getAge() {
        return age;
    }

    //返回可变对象的不可变视图
    public List<String> getHobbies() {
        return Collections.unmodifiableList(hobbies);
        // 或者返回深拷贝：return new ArrayList<>(hobbies);
    }

    public String getName() {
        return name;
    }
}
